package exercise4;

public class Exercise10_10 {
    public static void main(String []args){

        queue my_queue=new queue();

        //增加
        for (int i=1;i<=21;i++){
            System.out.println(i);
            my_queue.enqueue(i);
        }

        //删除
        for (int i=1;i<=21;i++){
            System.out.println(my_queue.dequeue());
        }

    }
}

class queue{
    int[] element;
    int size;

    public queue(){
        element=new int[8];
    }

    public void enqueue(int value){
        if (size >= element.length) {
            //创建一个更大的数组
            int[] temp = new int[element.length*2];
            System.arraycopy(element, 0, temp, 0, element.length);
            element = temp;
        }
        element[size++] = value;
    }

    public int dequeue() {
        int v = element[0];

        for (int i = 0; i < size - 1; i++) {
            element[i] = element[i + 1];
        }
        size--;
        return v;
    }

    public boolean empty() {
        return size == 0;
    }

    public int getSize() {
        return size;
    }

}
